package war2100;

import java.awt.Image;
import java.awt.Toolkit;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;

public class Prototypes {
	public static final String TILE_EARTH = "EARTHTILE";
	public static final String TILE_ROCK = "ROCKTILE";
	public static final String TILE_NEST_DIFFICULT = "NESTDIFFICULT";
	public static final String TILE_NEST_EASY = "NESTEASY";
	public static final String TILE_NEST_NORMAL = "NESTNORMAL";
	public static final String NPC_PLAYER_PROTOTYP = "PLAYER_PROTOTYP";

	public static final int TYPE_EDITOR = 0;
	public static final int TYPE_GAME = 1;

	private HashMap<String, Object> imageList;
	private Object[] playerStartPos;

	public Prototypes(int type) {
		imageList = new HashMap<String, Object>();
		if (type == TYPE_EDITOR) {
			playerStartPos = new Image[4];
			for (int id = 0; id < 4; id++) {
				playerStartPos[id] = Toolkit.getDefaultToolkit().getImage("./img/helpentitys/SpielerPos_0" + (id + 1) + ".png");
			}

			imageList.put(TILE_EARTH, Toolkit.getDefaultToolkit().getImage("./img/tiles/EarthTile.png"));
			imageList.put(TILE_ROCK, Toolkit.getDefaultToolkit().getImage("./img/tiles/RockTile.png"));

			imageList.put(TILE_NEST_DIFFICULT, Toolkit.getDefaultToolkit().getImage("./img/helpentitys/Nest3.png"));
			imageList.put(TILE_NEST_NORMAL, Toolkit.getDefaultToolkit().getImage("./img/helpentitys/Nest2.png"));
			imageList.put(TILE_NEST_EASY, Toolkit.getDefaultToolkit().getImage("./img/helpentitys/Nest1.png"));

			imageList.put(NPC_PLAYER_PROTOTYP, Toolkit.getDefaultToolkit().getImage("./img/npc/PlayerPrototyp.png"));

		}
		else if (type == TYPE_GAME) {
			try {
				playerStartPos = new org.newdawn.slick.Image[4];
				for (int id = 0; id < 4; id++) {
					playerStartPos[id] = new org.newdawn.slick.Image("./img/helpentitys/SpielerPos_0" + (id + 1) + ".png");
				}
				imageList.put(TILE_EARTH, new org.newdawn.slick.Image("./img/tiles/EarthTile.png"));
				imageList.put(TILE_ROCK, new org.newdawn.slick.Image("./img/tiles/RockTile.png"));

				imageList.put(TILE_NEST_DIFFICULT, new org.newdawn.slick.Image("./img/helpentitys/Nest3.png"));
				imageList.put(TILE_NEST_NORMAL, new org.newdawn.slick.Image("./img/helpentitys/Nest2.png"));
				imageList.put(TILE_NEST_EASY, new org.newdawn.slick.Image("./img/helpentitys/Nest1.png"));

				imageList.put(NPC_PLAYER_PROTOTYP, new org.newdawn.slick.Image("./img/npc/PlayerPrototyp.png"));
			}
			catch (Exception ex) {
				Logger.getLogger("").log(Level.SEVERE, ex.getMessage());
			}
		}
	}

	/**
	 * Liefert das Bild für den Spieler mit ID id
	 * 
	 * @param id
	 *            Niedrigster Wert 1
	 */
	public Image getPlayerStartPos(int id) {
		if (id < 1 && id > 4) {
			throw new IllegalArgumentException("ID ungültig.");
		}
		return (Image) playerStartPos[id - 1];
	}

	public void setPlayerStartPos(Image playerStartPos, int id) {
		if (id < 1 && id > 4) {
			throw new IllegalArgumentException("ID ungültig.");
		}
		this.playerStartPos[id - 1] = playerStartPos;
	}

	public Image getImage(String name) {
		return (Image) imageList.get(name);
	}

	public org.newdawn.slick.Image getSlickImage(String name) {
		return (org.newdawn.slick.Image) imageList.get(name);
	}
}
